﻿using System;
using System.Data;
using CoreLab.Oracle; //using Devart.Data.Oracle; //using Oracle.DataAccess.Client;
using System.Web;
using System.Web.Caching;


using LMD.Constant;
using LMD.Lib.Oracle;

namespace Cached
{
    /// <summary>
    /// Summary description for ProfileSummary
    /// </summary>
    public class ProfileSummary : CacheAbstraction
    {
        public DataTable GetProfileSummaryList()
        {
            return GetProfileSummaryList(false);
        }
        public DataTable GetProfileSummaryList(bool bForceRefresh)
        {
            String sxCacheKey = KCache.PROFILE_SUMMARY;

            if(bForceRefresh)
            {
                HttpRuntime.Cache.Remove(sxCacheKey);
            }

            if (HttpRuntime.Cache[sxCacheKey] == null)
            {
                DBLib dbl = new DBLib();

                String sxQuery =
                    @"
                    select
                        p1.P_CUSTOMER_INFO_SUMMARY_ID ID,
                        p1.TEXT,
                        case when nvl(p1.VALID_TO, SysDate+1) > SysDate
                            then 'Y'
                        else 'N'
                        end VALIDITY,
                        p1.P_CUSTOMER_INFO_TYPE_ID INFO_TYPE_ID,
                        p2.CODE INFO_TYPE
                    from 
                        P_CUSTOMER_INFO_SUMMARY p1
                        left join P_CUSTOMER_INFO_TYPE p2                    
                            on p1.P_CUSTOMER_INFO_TYPE_ID = p2.P_CUSTOMER_INFO_TYPE_ID 
                    order by
                        p2.CODE ASC
                    ";

                DataTable dt = dbl.GetDataTable(sxQuery);

                AddToCache(sxCacheKey, dt, CacheType.Daily);
                
            }
            return (DataTable)HttpRuntime.Cache[sxCacheKey];
        }        

        public override String GetCacheFilename()
        {
            return KCache.Filename.PROFILE_SUMMARY;
        }
    }
}